home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_gtk+.idb / usr / freeware / info / gtk.info-5.z / gtk.info-5
Encoding:
GNU Info File  |  1999-07-16  |  8.1 KB  |  264 lines

  1. This is Info file gtk.info, produced by Makeinfo version 1.68 from the
  2. input file gtk.texi.
  3.  
  4.    This file documents GTK, the GIMP Toolkit
  5.  
  6.    Copyright (C) 1996 Peter Mattis Copyright (C) 1997 Peter Mattis
  7.  
  8.    Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies
  11.  
  12.    Permission is granted to copy and distribute modified versions of
  13. this manual under the conditions for verbatim copying, provided that the
  14. entire resulting derived work is distributed under the terms of a
  15. permission notice identical to this one.
  16.  
  17.    Permission is granted to copy and distribute translations of this
  18. manual into another language, under the above conditions for modified
  19. versions, except that this permission notice may be stated in a
  20. translation approved by Peter Mattis.
  21.  
  22. INFO-DIR-SECTION User Interface Toolkit
  23. START-INFO-DIR-ENTRY
  24. * GTK: (gtk).        The GIMP Toolkit
  25. END-INFO-DIR-ENTRY
  26.  
  27. 
  28. File: gtk.info,  Node: Hello World,  Next: Hello World II,  Prev: Simple,  Up: Examples
  29.  
  30. Hello world in GTK
  31. ==================
  32.  
  33.      #include <gtk/gtk.h>
  34.      
  35.      int
  36.      main (int argc, char *argv[])
  37.      {
  38.        GtkWidget *window;
  39.        GtkWidget *label;
  40.      
  41.        gtk_init (&argc, &argv);
  42.      
  43.        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  44.        gtk_container_border_width (GTK_CONTAINER (window), 10);
  45.      
  46.        label = gtk_label_new ("Hello World");
  47.        gtk_container_add (GTK_CONTAINER (window), label);
  48.        gtk_widget_show (label);
  49.      
  50.        gtk_widget_show (window);
  51.      
  52.        gtk_main ();
  53.      
  54.        return 0;
  55.      }
  56.  
  57. 
  58. File: gtk.info,  Node: Hello World II,  Next: Hello World III,  Prev: Hello World,  Up: Examples
  59.  
  60. An enhanced hello world
  61. =======================
  62.  
  63.      #include "gtk.h"
  64.      
  65.      void
  66.      hello (void)
  67.      {
  68.        g_print ("Hello World\n");
  69.        gtk_exit (0);
  70.      }
  71.      
  72.      int
  73.      main (int argc, char *argv[])
  74.      {
  75.        GtkWidget *window;
  76.        GtkWidget *button;
  77.      
  78.        gtk_init (&argc, &argv);
  79.      
  80.        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  81.        gtk_container_border_width (GTK_CONTAINER (window), 10);
  82.      
  83.        button = gtk_button_new_with_label ("Hello World");
  84.        gtk_signal_connect (GTK_OBJECT (button), "clicked",
  85.                    GTK_SIGNAL_FUNC (hello), NULL);
  86.        gtk_container_add (GTK_CONTAINER (window), button);
  87.        gtk_widget_show (button);
  88.      
  89.        gtk_widget_show (window);
  90.      
  91.        gtk_main ();
  92.      
  93.        return 0;
  94.      }
  95.  
  96. 
  97. File: gtk.info,  Node: Hello World III,  Prev: Hello World II,  Up: Examples
  98.  
  99. Making Hello World II robust
  100. ============================
  101.  
  102.      #include "gtk.h"
  103.      
  104.      void
  105.      hello (void)
  106.      {
  107.        g_print ("Hello World\n");
  108.        gtk_exit (0);
  109.      }
  110.      
  111.      void
  112.      destroy (void)
  113.      {
  114.        gtk_exit (0);
  115.      }
  116.      
  117.      int
  118.      main (int argc, char *argv[])
  119.      {
  120.        GtkWidget *window;
  121.        GtkWidget *button;
  122.      
  123.        gtk_init (&argc, &argv);
  124.      
  125.        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  126.        gtk_signal_connect (GTK_OBJECT (window), "destroy",
  127.                    GTK_SIGNAL_FUNC (destroy), NULL);
  128.        gtk_container_border_width (GTK_CONTAINER (window), 10);
  129.      
  130.        button = gtk_button_new_with_label ("Hello World");
  131.        gtk_signal_connect (GTK_OBJECT (button), "clicked",
  132.                    GTK_SIGNAL_FUNC (hello), NULL);
  133.        gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
  134.                       GTK_SIGNAL_FUNC (gtk_widget_destroy),
  135.                       GTK_OBJECT (window));
  136.        gtk_container_add (GTK_CONTAINER (window), button);
  137.        gtk_widget_show (button);
  138.      
  139.        gtk_widget_show (window);
  140.      
  141.        gtk_main ();
  142.      
  143.        return 0;
  144.      }
  145.  
  146. 
  147. File: gtk.info,  Node: Object Implementation,  Next: Signal Implementation,  Prev: Examples,  Up: Top
  148.  
  149. Object internals
  150. ****************
  151.  
  152.    Objects (or the `GtkObject' type) and the class hierarchy in general
  153. is implemented via a hierarchy of structs and type casting. Be aware
  154. that when classes are mentioned it is the conceptual idea of classes
  155. that is being referred to. GTK is written entirely in C which provides
  156. no direct support for classes.
  157.  
  158.    The first part to the class mechanism is the object fields. These are
  159. fields that will be used on a per object basis. For example, the widget
  160. type contains a field for the widgets parent. Every derived type needs a
  161. reference to its parent type. A descendant class of `GtkObject' would
  162. define itself like:
  163.  
  164.      struct Descendant
  165.      {
  166.        GtkObject object;
  167.      
  168.        ...
  169.      };
  170.  
  171.    It is important to note that the `GtkObject' field needs to appear
  172. first in the descendant type structure. This allows pointers to objects
  173. of type `Descendant' to be cast to pointers to `GtkObject''s and
  174. vice-versa.
  175.  
  176.    The second part to the class mechanism is the class fields. These
  177. fields are defined on a per class basis. In the case of widgets, the
  178. class fields are all the "virtual" functions for widgets. The
  179. `GtkObject' class defines the `destroy' virtual function and the
  180. necessary fields for the signal mechanism as well as a field for
  181. determining the runtime type of an object. A virtual function is
  182. semantically the same as it is in C++. That is, the actual function that
  183. is called is determined based on the type of the object. Or, more
  184. specifically, the actual function call depends on the class structure
  185. that is pointed to by the `klass' field of the `GtkObject' structure.
  186.  
  187.    To see how the class fields work it is necessary to see the object
  188. fields for a `GtkObject'. The `GtkObject' type is defined as follows:
  189.  
  190.      typedef struct _GtkObject GtkObject;
  191.      
  192.      struct _GtkObject
  193.      {
  194.        guint32 flags;
  195.        GtkObjectClass *klass;
  196.        gpointer object_data;
  197.      };
  198.  
  199.    The `class' field actually points to a class structure derived from
  200. `GtkObjectClass'. By convention, each new type defines its own class
  201. structure even if it is unnecessary. As an example, the hypothetical
  202. `Descendant' class would define its class structure as:
  203.  
  204.      struct DescendantClass
  205.      {
  206.        GtkObjectClass parent_class;
  207.      
  208.        ...
  209.      };
  210.  
  211.    It is convention to name the parent class field (`GtkObjectClass' in
  212. this case), `parent_class'. For the same reason as stated above for the
  213. object structure, the parent class field must be the first field in the
  214. class structure.
  215.  
  216.    *Note:* GTK assumes that the first field in a structure will be
  217. placed by the compiler at the start of the structure. This is certainly
  218. true for gcc, however, from my precursory reading of the C standard I
  219. was unable to come to a definite conclusion as to whether this was
  220. required or simply done for simplicity. I'm not too worried about this
  221. assumption, though, as every C compiler I've ever encountered would work
  222. with GTK.
  223.  
  224.    The `flags' field of the `GtkObject' structure is used to keep track
  225. of a relatively few object flags and is also used by the `GtkWidget'
  226. type to store additional flags. At this time, the upper 16 bits of the
  227. flags field are reserved but unused.
  228.  
  229.    The `object_data' field of the `GtkObject' structure is an opaque
  230. pointer used by the object data mechanism. In truth, it is a pointer to
  231. the beginning of the data list which is composed of the following
  232. structures.
  233.  
  234.      typedef struct _GtkObjectData GtkObjectData;
  235.      
  236.      struct _GtkObjectData
  237.      {
  238.        guint id;
  239.        gpointer data;
  240.        GtkObjectData *next;
  241.      };
  242.  
  243.    The data mechanism allows arbitrary data to be associated with a
  244. character string key in any object. A hash table is used to transform
  245. the character string key into the data id and then a search through the
  246. list is made to see if the data exists. The assumption being that the
  247. data list will usually be short and therefore a linear search is OK.
  248. Future work on the data mechanism might make use of a resizable array
  249. instead of a linked list. This would shrink the overhead of the
  250. `GtkObjectData' structure by 4 bytes on 32 bit architectures.
  251.  
  252. 
  253. File: gtk.info,  Node: Signal Implementation,  Next: Widget Implementation,  Prev: Object Implementation,  Up: Top
  254.  
  255. Signal internals
  256. ****************
  257.  
  258. 
  259. File: gtk.info,  Node: Widget Implementation,  Next: Function Index,  Prev: Signal Implementation,  Up: Top
  260.  
  261. Widget internals
  262. ****************
  263.  
  264.